package com.mes.schedule.manager.iface;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.mes.basicdata.domain.Routing;
import com.mes.common.manager.iface.IBasicManager;
import com.mes.schedule.domain.SOperationTask;
import com.mes.schedule.domain.SPartTask;
import com.mes.schedule.domain.ScheduleScheme;
import com.mes.task.domain.PartTask;

/**
 * 零件任务管理 ClassName: SchedulePartTaskManager <br/> Function: TODO ADD FUNCTION.
 * <br/> Reason: TODO ADD REASON. <br/> date: Jun 22, 2015 9:09:15 PM <br/>
 * 
 * @author Administrator
 * @version
 * @since JDK 1.6
 */
public interface ISchedulePartTaskManager extends IBasicManager {

	public List<SPartTask> filter(Collection<SPartTask> partTaskList,
			Map parameters);

	public void setStartEndTimeOfPartTask(SPartTask partTask);

	public void initRemainWork(SPartTask partTask, SOperationTask timeStone);

	// public void setPriority(SPartTask partTask);

	public void setNextTimeStone(SPartTask partTask);

	public void autoCombineBatch(ScheduleScheme scheme) throws Exception;

	public void calcSlack(SPartTask partTask);

	public void sortByPriorityAndSlack(List<SPartTask> partTaskList);

	public void sortByPriorityDrawingIdAndBatchNum(List<SPartTask> partTaskList);

	public void calcSlack(SPartTask partTask,
			SOperationTask currentOperationTask);

	public SPartTask combineBatch(List<SPartTask> combineBatchList, int mode)
			throws Exception;

	public void removeBatchFromCombinedBatch(ScheduleScheme scheme,
			String combinedTaskUid, String removedBatchNums) throws Exception;

	public void cancelCombineBatch(ScheduleScheme scheme, String taskUid)
			throws Exception;

	public void cancelAllCombineBatch(ScheduleScheme scheme) throws Exception;

	public List<SPartTask> splitBatch(SPartTask partTask,
			List<SOperationTask> splitedBatch) throws Exception;

	public void cancelSplitBatchWithEvent(SPartTask partTask,
			List<SPartTask> splitedBatchs) throws Exception;

	/**
	 * 分批的同时创建事件
	 * 
	 * @param partTask
	 * @param splitedBatch
	 * @return
	 * @throws Exception
	 */
	public List<SPartTask> splitBatchWithEvent(SPartTask partTask,
			List<SOperationTask> splitedBatch) throws Exception;

	public void compressOperationTaskByPartTask(SPartTask partTask);

	// add by zy
	// 删除零件任务
	public void deletePartTask(SPartTask partTask) throws Exception;

	/**
	 * 根据iSRemoveFromDB判断是否从数据库中移除
	 * 
	 * @param partTask
	 * @param iSRemoveFromDB
	 * @throws Exception
	 */
	public void removePartTask(SPartTask partTask, Boolean iSRemoveFromDB)
			throws Exception;

	public void createDefaultLink(SPartTask partTask);

	public void updatePartTask(SPartTask partTask1, SPartTask partTask2);

	public void updatePartTask(ScheduleScheme scheme, SPartTask partTask)
			throws Exception;

	public void addPartTask(ScheduleScheme scheme, SPartTask partTask)
			throws Exception;

	// 保存某一零件任务中的工序任务
	public void savePartTask(ScheduleScheme scheme, List<SPartTask> partTaskList)
			throws Exception;

	public void completePartTask(SPartTask partTask) throws Exception;

	public String getNetChartXml(ScheduleScheme scheme, String partTaskUid)
			throws Exception;

	public void applyRouting(String scheduleUid, String partTaskUid,
			String routingUid, String currentOperationIdDesc) throws Exception;

	// 将计划数据反写回routing
	public void backToRouting(String scheduleUid, String partTaskUid)
			throws Exception;

	/**
	 * add by zy 将计划工艺反写回主制工段的基础工艺
	 * 
	 * @param scheduleUid
	 * @param partTaskUid
	 * @throws Exception
	 */
	public void backToMasterScheduleRouting(String masterScheduleUid,
			SOperationTask masterOperationTask) throws Exception;

	public void refreshSlackAndColor(ScheduleScheme scheme,
			Collection<SPartTask> partTasks) throws Exception;

	/**
	 * 选择零件任务是否进入调度
	 * 
	 * @param partTaskList
	 * @throws Exception
	 */
	public void intoSchedule(List<SPartTask> partTaskList) throws Exception;

	public void intoSchedule(SPartTask partTask) throws Exception;

	public void outSchedule(List<SPartTask> partTaskList, Boolean isWaiting)
			throws Exception;

	/**
	 * 移出调度
	 * 
	 * @param partTask
	 * @param isWaiting
	 *            是否进入等待调度区
	 * @throws Exception
	 */
	public void outSchedule(SPartTask partTask, Boolean isWaiting)
			throws Exception;

	/**
	 * 刷新工序距离
	 * 
	 * @param partTask
	 * @throws Exception
	 */
	public void refreshTaskDistance(SPartTask partTask) throws Exception;

	/**
	 * 清除本调度方案中所有零组件任务交货期的设置
	 * 
	 * @param scheme
	 * @throws Exception
	 */
	public void clearLateFinish(ScheduleScheme scheme) throws Exception;

	/**
	 * 先清除本调度方案中所有零组件任务交货期的设置，然后按照指令对接情况重新设置交货期。
	 * 
	 * @param scheme
	 * @throws Exception
	 */
	public void syncLateFinish(ScheduleScheme scheme) throws Exception;

	/**
	 * 按照交货期重置排产集，将有交货期的任务移入排产集，无交货期的任务移出排产集。
	 * 
	 * @param scheme
	 * @throws Exception
	 */
	public void resetScheduleCol(ScheduleScheme scheme) throws Exception;

	/**
	 * 取得MES中原始的零件任务
	 * 
	 * @param partTask
	 * @return
	 * @throws Exception 
	 */
	PartTask getOPartTask(SPartTask partTask) throws Exception;

	Set<PartTask> getOPartTasks(SPartTask partTask) throws Exception;

	/**
	 * 通过MES中的任务来获取调度任务
	 * 
	 * @param originPartTask
	 * @return
	 */
	SPartTask getSchedulePartTask(ScheduleScheme scheme, PartTask originPartTask);

	public void changePartTaskQty(ScheduleScheme scheme, SPartTask partTask,
			Double newPlanQty) throws Exception;

	/**
	 * 初始化调度中的零件任务
	 * 
	 * @param scheme
	 * @param partTask
	 */
	public void init(ScheduleScheme scheme, SPartTask partTask);

	/**
	 * 应用新工艺路线
	 * 
	 * @param scheme
	 * @param partTask
	 * @param routing
	 * @param currentOperationIdDesc
	 * @throws Exception
	 */
	public void applyRouting(ScheduleScheme scheme, SPartTask partTask,
			Routing routing, String currentOperationIdDesc) throws Exception;

	/**
	 * 移除调度，自动判断是否应处于等待状态
	 * 
	 * @param outPartTask
	 * @throws Exception
	 */
	public void outSchedule(SPartTask outPartTask) throws Exception;

	/**
	 * 
	 * 取得某一个零件的当前工序号
	 * 
	 * @param scheme
	 * @param partTask
	 * @return
	 */

	public String getCurrentOperationIdDesc(ScheduleScheme scheme,
			SPartTask partTask);

	public SPartTask getCombineBatch(SPartTask partTask);

	/**
	 * 刷新成组零件任务信息
	 * 
	 * @param combinePartTask
	 */
	public void refreshCombineBatch(SPartTask combinePartTask);

	/**
	 * 取得零件任务
	 * 
	 * @param scheduleUid
	 * @param partTaskUid
	 * @return
	 */
	public SPartTask getSchedulePartTask(String scheduleUid, String partTaskUid);

	/**
	 * 临时导入在制品任务
	 * 
	 * @param partTask
	 * @param currentOperationIddesc
	 * @throws Exception
	 */
	public void importFromWip(SPartTask partTask, String currentOperationIddesc)
			throws Exception;

	public SPartTask getSchedulePartTask(ScheduleScheme scheme, String partUid,
			String batchNum);

	public void sortByDrawingIdAndBatchNum(List<SPartTask> partTaskList);

	/**
	 * 取消分批
	 * 
	 * @param mainBatch
	 * @param splitedBatchs
	 * @throws Exception
	 */
	public void cancelSplitBatch(SPartTask mainBatch,
			List<SPartTask> splitedBatchs) throws Exception;

	public List<SPartTask> filterPrecise(
			Collection<SPartTask> schedulePartTasks, Map parameters);

	public List<SPartTask> filterCanCombineBatch(
			Collection<SPartTask> schedulePartTasks, Map parameters);

	/**
	 * 新建基础工艺by hba
	 * 
	 * @param scheduleUid
	 * @param taskUid
	 * @param routingType
	 * @param productPhase
	 * @param routingName
	 * @param versionId
	 * @param isDefault
	 * @throws Exception 
	 */
	public void newRouting(String scheduleUid, String taskUid,
			String versionId, String routingName, String productPhase,
			String routingType, boolean isDefault) throws Exception;

	public List<SOperationTask> getOpTaskListForShiftProduction(
			ScheduleScheme scheme, SPartTask partTask) throws Exception;

}
